import {getInviteRecords} from "@src/api/member";

Component({
  data: {
    pageNum: 1,
    pageSize: 10,
    loading: false,
    listData: [],
    hasNextPage: false
  },
  methods: {
    onLoad() {
      this.fetchData();
    },
    onPullDownRefresh() {
      wx.stopPullDownRefresh();
      this.setData({listData: [], pageNum:1, pageSize: 10})
      this.fetchData();
    },
    onReachBottom() {
      if (this.data.hasNextPage) {
        this.setData({pageNum:this.data.pageNum + 1})
        this.fetchData();
      }
    },
    fetchData() {
      let data = {
        page: this.data.pageNum,
        pageSize: this.data.pageSize,
      }
      this.setData({loading: true})
      getInviteRecords(data).then(res => {
        this.setData({loading: false})
        if (res.code === 0) {
          let listData = this.data.listData.concat(res.data.list)
          this.setData({listData, hasNextPage: res.data.hasNextPage})
        }
      }).catch(()=> {
        this.setData({loading: false})
      })
    },

  }
})
